<template>
      <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true" rowSelection="multiple" @grid-ready="gridReady" style="height: 100%;" class='ag-theme-alpine'
        :defaultColDef="defaultColDef" :rowData="table.dataList" :columnDefs="cfsValue"
        :localeText="localeTextData" />
</template>

<script lang="ts">
import { ref, onMounted } from 'vue';

import { localeText } from '@/api/aggridZw'
import emitter from '@/hooks/useEventBus'
import { useTable } from '@/hooks/table';
import { Message } from '@arco-design/web-vue';
import { assTable } from '@/utils/assemblyLevelTable';
import { wordProcess } from '@/api/DyeingshopManagement/getOrderFn';
export default {
    name:'workShopSpeed',
    props:{
        flowCardCode:{
            type:String,
            default:''
        }
    },
   setup(props){
    const gridOption = ref(); 
    const table = useTable();
    const gridReady = (params: any) => {
        gridOption.value = params.api;
    };
    const defaultColDef = {
        sortable: true,
        resizable: true,
        filter: true,
        // flex: 1,
        width: 150,
    };
    onMounted(async () => {
        await wordProcess().getWordProcessList({ flowCardCode: props.flowCardCode }).then((res: any) => {
        if (res.code === 200) {
          let rData = res.data;
          let rList = rData.map((v: any) => {
            return {
              ...v.WorkshopProcessDetailed
            }
          });
          table.handleSuccess(rList)
          gridOption.value.setRowData(rList);
        } else {
          Message.error(res.message);
        }
      }).catch((err) => { console.log(err) })
    });
    let cfsValue:any[] = [
            {
                headerName: '流转卡号',
                field: 'flowCardCode',
            },
            {
                headerName: '工序',
                field: 'process',
            },
            {
                headerName: '性质',
                field: 'roamCard',
            },
            {
                headerName: '匹数',
                field: 'canUseHouseNum',
            },
            {
                headerName: '工序计划开始时间',
                field: 'planBeginTime',
            },
            {
                headerName: '工序计划结束时间',
                field: 'planFinshTime',
            },
            {
                headerName: '工序实际开始时间',
                field: 'realityBeginTime',
            },
            {
                headerName: '工序实际结束时间',
                field: 'realityFinishTime',
            }, 
            {
                headerName: '重量',
                field: 'canUseWeight',
            },
            {
                headerName: '车间',
                field: 'workshop',
            },
            {
                headerName: '开始班次',
                field: 'beginClasses',
            },
            {
                headerName: '结束班次',
                field: 'finishClasses',
            },
            {
                headerName: '开始班组',
                field: 'grayCode',
            },
            {
                headerName: '结束班组',
                field: 'grayName',
            },
            {
                headerName: '开始员工',
                field: 'beginStaff',
            },
            {
                headerName: '结束员工',
                field: 'finishStaff',
            },
        ];
    const localeTextData: any = ref(localeText);
    let a = [{
            showRowGroup: 'hide_def',
            "headerName": "",
            "checkboxSelection": true,
            "headerCheckboxSelection": true,
            "pinned": "left",
            "width": 50,
            resizable: false,
            filter: false,
            sortable: false,
            minWidth: 50,
            maxWidth: 50,
            lockPosition: "left",
        }];
    cfsValue = a.concat(cfsValue);
    emitter.on('export-cylinderDetailInfo', () => {
            let selectList = gridOption.value.getSelectedRows();
            // console.log(selectList);
            if (selectList.length === 0) {
                Message.error('请勾选需要导出的数据')
                return
            } else {
                //导出数据
                let nowRow = table.dataList.filter(function (o) {
                    return (gridOption.value.getSelectedRows().map((o: any) => { return o.id })).indexOf(o["id"]) !== -1;
                })
                assTable(cfsValue, nowRow, '车间进度');
            }
        });
    return {
        table,
        defaultColDef,
        localeTextData,
        gridReady,
        cfsValue
    }
   }
}
</script>

<style scoped>

</style>